<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="./vue-event-util.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        body{
            padding: 0;
            margin: 0;
        }
        .example{
            max-width: 250px;
            padding: 10px;
        }
        .example .text{
            font-size: 12px;
            color: #de5c5c;
        }
        .example button{
            width: 100%;
            margin-left: 0!important;
            margin: 10px 0!important;
        }
    </style>
</head>
<body>

    <div id="app">
            <el-row>
                <el-col :xs="24" :md="6"><div class="example">
                    <p>每次点击都会弹出一个按钮</p>
                    <p class="text">请在1秒内连续点击下面的按钮，点击几次会弹几个消息框</p>
                    <el-button type="primary" @click="click()">请连击我</el-button>
                </div></el-col>
                <el-col :xs="24" :md="6"><div class="example">
                    <p>使用throttle防止连击，1秒内保护按钮只能响应一次点击事件</p>
                    <p class="text">请在1秒内连续点击下面的按钮，无论点击几次只会弹一个消息框</p>
                    <!-- 使用$throttle确保click事件1秒内只响应一次 -->
                    <el-button type="primary" @click="$throttle(click, 1000)()">请连击我</el-button>
                </div></el-col>
                <el-col :xs="24" :md="6"><div class="example">
                        <p>循环渲染时候，如果不绑定key，所有按钮一秒内只能响应一次单击请求</p>
                        <p class="text">请在1秒内连续连击下面的按钮1、按钮2、按钮3，1秒内只会弹一次最先单击那个按钮的消息框</p>
                        <!-- 未将key传入throttle -->
                        <el-button v-for="key in 3" :key="key" type="primary" @click="$throttle(click, 1000)(key)">按钮{{key}}</el-button>
                </div></el-col>
                <el-col :xs="24" :md="6"><div class="example">
                        <p>循环渲染时候，如果绑定key，每个按钮一秒内只能响应一次，彼此互不干扰</p>
                        <p class="text">请在1秒内连续连击下面的按钮1、按钮2、按钮3，每个按钮的对话框无论点击几次只会弹一个消息框</p>
                        <!-- 将key传入throttle -->
                        <el-button v-for="key in 3" :key="key" type="primary" @click="$throttle(key, click, 1000)(key)">按钮{{key}}</el-button>
                </div></el-col>
            </el-row>
        </div>
    </div>
    <script>
        Vue.use(vueEventUtil)
        var app = new Vue({
            el: '#app',
            methods: {
                click(name = ''){
                    const h = this.$createElement;
                    this.$notify({
                        title: '标题名称' + name,
                        message: h('i', { style: 'color: teal'}, '消息' + name),
                        duration: 1000
                    });
                },
            }
        })
    </script>
</body>
</html>
